package linuxbox.news.logic;

import java.sql.Timestamp;
import linuxbox.BoxStatic;

public class BoxNewsEntry {
    protected int id = 0;
    protected Timestamp subTime;
    protected Timestamp expTime;
    protected String subject = "";
    protected String content = "";

    public void copyFrom(BoxNewsEntry entry) {
        id = entry.getId();
        if (entry.getSubject() == null)
            subject = null;
        else
            subject = new String(entry.getSubject());
        if (entry.getContent() == null)
            content = null;
        else
            content = new String(entry.getContent());
        if (entry.getSubTime() == null)
            subTime = null;
        else
            subTime = new Timestamp(entry.getSubTime().getTime());
        if (entry.getExpTime() == null)
            expTime = null;
        else
            expTime = new Timestamp(entry.getExpTime().getTime());
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Timestamp getSubTime() {
        return subTime;
    }

    public void setSubTime(Timestamp tm) {
        subTime = tm;
    }

    public String getSubTimeString() {
        if (subTime == null)
            return "";
        else {
            BoxStatic.dateTimeFormatter
                    .applyPattern(BoxStatic.SHORT_DATE_FORMAT);
            return BoxStatic.dateTimeFormatter.format(subTime);
        }
    }

    public Timestamp getExpTime() {
        return expTime;
    }

    public void setExpTime(Timestamp tm) {
        expTime = tm;
    }

    public String getExpTimeString() {
        if (expTime == null)
            return "";
        else {
            BoxStatic.dateTimeFormatter
                    .applyPattern(BoxStatic.SHORT_DATE_FORMAT);
            return BoxStatic.dateTimeFormatter.format(expTime);
        }
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String s) {
        subject = s;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String s) {
        content = s;
    }

    public String toString() {
        String s = "id=" + id + ", m_sSubject=" + subject
                + ", m_sContent=" + content + ", m_SubTime=" + subTime
                + ", m_ExpTime=" + expTime + "\n";
        return s;
    }
}
